#ifndef FORTE_SIMPLE_STRING_HPP
#define FORTE_SIMPLE_STRING_HPP

#include <cstddef>
#include <cstring>
#include <vector>

namespace Forte
{
  class SimpleString
  {
  public:
    SimpleString(char const* data);
    SimpleString(char const* data, std::size_t length);

    char const* GetData() const;
    std::size_t GetLength() const;
    bool StartsWith(SimpleString const& s) const;
    void Split(char separator, std::vector<SimpleString>& output) const;
    bool operator==(char const* s) const;
    bool operator==(SimpleString const& s) const;
    bool operator==(std::string const& s) const;
    std::string ToString() const;
  private:
    char const*   mData;
    std::size_t   mLength;
  };
};

inline Forte::SimpleString::SimpleString(char const* data)
  : mData(data)
  , mLength(strlen(data))
{}

inline Forte::SimpleString::SimpleString(char const* data, std::size_t length)
  : mData(data)
  , mLength(length)
{}

inline char const* Forte::SimpleString::GetData() const
{
  return mData;
}

inline std::size_t Forte::SimpleString::GetLength() const
{
  return mLength;
}

inline bool Forte::SimpleString::StartsWith(SimpleString const& s) const
{
  return mLength >= s.GetLength() && (0 == memcmp(mData, s.GetData(), s.GetLength()));
}

inline void Forte::SimpleString::Split(char separator, std::vector<SimpleString>& output) const
{
  char const* begin = mData;
  char const* const end = mData + mLength;
  for(char const* s = mData; s != end; ++s)
  {
    if (*s == separator)
    {
      output.push_back(SimpleString(begin, s-begin));
      begin = s + 1;
    }
  }
  output.push_back(SimpleString(begin, end-begin));
}

inline bool Forte::SimpleString::operator==(char const* s) const
{
  return *this == SimpleString(s);
}

inline bool Forte::SimpleString::operator==(SimpleString const& s) const
{
  return mLength == s.GetLength() && (0 == memcmp(mData, s.GetData(), mLength));
}

inline bool Forte::SimpleString::operator==(std::string const& s) const
{
  return mLength == s.length() && (0 == memcmp(mData, s.c_str(), mLength));
}

inline std::string Forte::SimpleString::ToString() const
{
  return std::string(mData, mLength);
}

#endif

